package com.lujianfei.powerinput.ui.template;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.lujianfei.powerinput.R;
import com.lujianfei.powerinput.base.BaseActivity;
import com.lujianfei.powerinput.database.TemplateModel;
import com.lujianfei.powerinput.ui.template.base.TemplateAddContract;
import com.lujianfei.powerinput.ui.template.presenter.TemplateAddPresenter;
import com.lujianfei.powerinput.widget.input.TextInput;

import androidx.annotation.Nullable;

public class TemplateAddActivity extends BaseActivity implements TemplateAddContract.View {

    private TemplateAddContract.Presenter presenter;
    private LinearLayout container;
    private Button bt_add_field;
    private TemplateModel data;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_template_add);
        initView();
        initEvent();
        setTitleMiddleText("添加模板");
        showTitleRightImage();
        setTitleRightImage(R.drawable.ic_ok);
        presenter = new TemplateAddPresenter(this);
        parseIntent();
        presenter.init();
    }

    private void parseIntent() {
        Intent intent = getIntent();
        data = intent.getParcelableExtra("data");
        presenter.setData(data);
    }

    @Override
    public void onTitleRightImageClick() {
        super.onTitleRightImageClick();
        presenter.onTitleRightImageClick();
    }

    private void initEvent() {
        bt_add_field.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                presenter.addRow();
            }
        });
    }

    private void initView() {
        container = findViewById(R.id.container);
        bt_add_field = findViewById(R.id.bt_add_field);
    }

    @Override
    protected int getTitleBarResId() {
        return R.id.custom_titlebar;
    }

    @Override
    public LinearLayout getContainer() {
        return container;
    }

    @Override
    public Activity currentActivity() {
        return this;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        presenter.onActivityResult(requestCode,resultCode,data);
    }
}
